<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

if(!defined('TinyFW')) exit('Access denied!');

class tfUrl{
    
    private $protocol = null;
    private $base_url = null;
    private static $instance = null;



    
    private function _generate_site($action = null, $module = null, $app = null) {
        
        $app = empty($app) ? tfUri::getAppName() : $app;
        $module = empty($module) ? tfUri::getModuleName() : $module;
        $action = empty($action) ? tfUri::getActionName() : $action;

        $site = $this->protocol . $this->base_url . $app . "/" . $module . "/" . $action . "/";
        return $site;
        
    }

    private function  __construct() {
        //set protocol
        $this->_set_protocol();
        $this->_set_base_url();
    }

    public static function singleton(){
        if(! isset(self::$instance)) {
            self::$instance = new self();
        }
        return self::$instance;
    }
    
    private function _set_protocol() {
        if($_SERVER['HTTPS']) {
            $this->protocol = 'HTTPS://';
        } else {
            $this->protocol = 'HTTP://';
        }
    }

    private function _set_base_url() {
            $this->base_url = WEB_ROOT;
    }
    
    public static function site($action = null , $module = null, $app = null) {
        return self::singleton()->_generate_site($action, $module, $app);
    }

}

?>
